/**
 * TODO 1.需要对owner进行测试 2.需要对id自增进行测试（多个交互者）
 */
import { expect } from "chai";
import { ethers } from "hardhat";
import {getMock}  from '../scripts/chainLink/VRFCoordinatorV2Mock';
let mockContract:Contract;
let randomDogNFTContract:any;
let subscriptionId;
const keyHash='0xd89b2bf150e3b9e13446986e571fb9cab24b13cea0a43ea20a6049a85cc807cc';
describe("Test RandomDogNFT", ()=>{
    
    it("TestRandom",async()=>{
        // let siners=await ethers.getSigners();//获取签名者
        // let deployer=siners[0];
        // randomDogNFTContract=await randomDogNFTContract.connect(deployer)
        // 发起request
       await  randomDogNFTContract.createCollectible('abandom');
       let requestId=await randomDogNFTContract.s_requestId();
       console.log('requestId为'+requestId);
            //  await mockContract.fulfillRandomWords(requestId,await VRFConsumerContract.getAddress()) ;

            await mockContract.fulfillRandomWords(requestId,await randomDogNFTContract.getAddress()) ; 
            // await randomDogNFTContract.fulfillRandomWords(requestId,randomDogNFTContract.s_randomWords());
    //    console.log('区块链一'+await deployer.provider.getBlockNumber())
    //  await ethers.provider.send("evm_mine", []); 
     await ethers.provider.send("evm_mine", []);
    //    console.log('区块链二'+await deployer.provider.getBlockNumber());
           //    触发mock回调
  
    //   mint NFT 
    // await randomDogNFTContract.s_randomWords(0);
    // await randomDogNFTContract.fulfillRandomWords(requestId,await randomDogNFTContract.s_randomWords());
       console.log('tokenCounter='+await randomDogNFTContract.tokenCounter());
       console.log('randomNum='+await randomDogNFTContract.s_randomWords(0));
    //    console.log('balance='+await randomDogNFTContract.balanceOf(deployer));
       console.log('')
    //    let requestId= await randomDogNFTContract.s_requestId();
    //    await mockContract.fulfillRandomWords(requestId,await mockContract.getAddress());
    })
    beforeEach(async()=>{
        let consumer;
        consumer=await getMock()
        mockContract=await consumer.VRFCoordinatorV2MockContract;
        const vrfCoordinatorAddress=await mockContract.getAddress();
        // 订阅
        let tx= await mockContract.createSubscription();
        let receipt=await tx.wait(1);
        subscriptionId=receipt.logs[0].topics[1]//获得订阅号
        // 充值
       await mockContract.fundSubscription(subscriptionId,BigInt(100000000000000000));
        randomDogNFTContract= await ethers.getContractFactory("RandomDogNFT");
        // 部署
        randomDogNFTContract=await randomDogNFTContract.deploy(vrfCoordinatorAddress,subscriptionId,keyHash);
        // 加入消费者
        await mockContract.addConsumer(subscriptionId,await randomDogNFTContract.getAddress());
    })
})

